package com.ittable.rpcdemo.server;

import com.ittable.rpcdmeo.service.HealthyService;

import java.net.MalformedURLException;
import java.rmi.AlreadyBoundException;
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;

import static com.ittable.rpcdmeo.constant.RmiConstant.RMI_NAME;

/**
 * @author srh
 * @date 2020/10/17
 **/
public class ServerMain {

    public static void main(String[] args) throws RemoteException, AlreadyBoundException, MalformedURLException {
        // 创建service对象，同时创建stub对象
        HealthyService service = new HealthyServiceImpl();

        // 创建本主机远程对象注册表Register实例，并指定8888端口
        LocateRegistry.createRegistry(8888);

        // 绑定URL标准格式( rmi://host:port/name , rmi 协议名可省略)
        Naming.bind(RMI_NAME, service);

        System.out.println("service bind already");
    }

}
